﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>商品档案列表</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="/Styles/demo.css" />
    <script src="/scripts/boot.js" type="text/javascript"></script>
</head>
<body>
    <div style="width: 100%">
        <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 100%;">
                        <a class="mini-button" iconcls="icon-add" onclick="editRow('')" plain="true">增加</a>
                        @*<a class="mini-button" iconcls="icon-remove" onclick="remove()" plain="true">删除</a>
                        <a class="mini-button" iconcls="icon-date-magnify" onclick="showSearchWindow()" plain="true">
                            筛选</a> *@<span class="separator"></span>
                    </td>
                    <td style="white-space: nowrap;">
                        <input id="ifexame" class="mini-combobox" textfield="text" valuefield="id" value=""
                            url="/Category/ExameItems" nullitemtext="--是否审核--" emptytext="--是否审核--" onvaluechanged="search()"/>
                        <input id="Id" class="mini-textbox" emptytext="请输入编码" style="width: 150px;" onenter="onKeyEnter" />
                        <a class="mini-button" onclick="search()">查询</a>
                    </td>
                </tr>
            </table>
            <div id="searchWindow" class="mini-window" title="高级筛选" style="width: 650px; height: 220px;"
                iconcls="icon-date-magnify" showmaxbutton="true" showtoolbar="true" showfooter="true"
                showmodal="false" allowresize="false" allowdrag="true">
                <div property="footer" style="text-align: right; padding: 5px; padding-right: 15px;">
                    <a class="mini-button" iconcls="icon-zoom" onclick="advSearch()" style='vertical-align: middle;'>
                        筛选</a>
                </div>
                <form id="frmAdv">
                <table class="edittable" border="1" cellpadding="0" cellspacing="0">
                    <tr>
                        <td style="width: 80px;">
                            店内码:
                        </td>
                        <td style="width: 120px;">
                            <input name="GoodsCode" class="mini-textbox" />
                        </td>
                        <td style="width: 80px;">
                            条形码:
                        </td>
                        <td style="width: 120px;">
                            <input name="GoodsBarCode" class="mini-textbox" />
                        </td>
                        <td style="width: 80px;">
                            商品简码:
                        </td>
                        <td style="width: 120px;">
                            <input name="GoodsSubCode" class="mini-textbox" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            大类:
                        </td>
                        <td>
                            <input name="GbCode" id="GbCode" class="mini-combobox" textfield="text" valuefield="id"
                                url="/category/GetFbPaGoodsGb/" shownullitem="true" />
                        </td>
                        <td>
                            中类:
                        </td>
                        <td>
                            <input name="GmCode" id="GmCode" class="mini-combobox" textfield="text" valuefield="id"
                                url="/Category/GetFbPaGoodsGm/" shownullitem="true" />
                        </td>
                        <td>
                            小类:
                        </td>
                        <td>
                            <input name="GsCode" id="GsCode" class="mini-combobox" textfield="text" valuefield="id"
                                url="/Category/GetFbPaGoodsGs/" shownullitem="true" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            细类:
                        </td>
                        <td>
                            <input name="GlCode" id="GlCode" class="mini-combobox" textfield="text" valuefield="id"
                                url="/Category/GetFbPaGoodsGl/" shownullitem="true" />
                        </td>
                        <td>
                            商品类型:
                        </td>
                        <td>
                            <input name="GoodsType" class="mini-textbox" />
                        </td>
                        <td>
                            核算方式:
                        </td>
                        <td>
                            <input name="CheckMode" class="mini-textbox" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            供货商:
                        </td>
                        <td>
                            <input name="SupCode" class="mini-textbox" />
                        </td>
                        <td>
                            经营方式:
                        </td>
                        <td>
                            <input name="OpCode" class="mini-textbox" />
                        </td>
                        <td>
                            扣率:
                        </td>
                        <td>
                            <input name="PoolRate" class="mini-spinner" decimalplaces="2" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            商品名称:
                        </td>
                        <td>
                            <input name="GoodsName" class="mini-textbox" />
                        </td>
                        <td>
                            商品简称:
                        </td>
                        <td>
                            <input name="GoodsSubName" class="mini-textbox" />
                        </td>
                        <td>
                            拼音码:
                        </td>
                        <td>
                            <input name="PyCode" class="mini-textbox" />
                        </td>
                    </tr>
                </table>
                </form>
            </div>
        </div>
    </div>
    <div class="mini-fit">
        <div class="mini-splitter" style="width: 100%; height: 100%;">
            <div size="340" showcollapsebutton="true">
                <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                    <input class="mini-textbox" id="treekey" style="width:150px;" />
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="treesearch">查找</a>
                </div>
                <div class="mini-fit">
                    <ul id="tree1" class="mini-tree" url="/Archives/SearchAllSuppliers" style="width: 100%;"
                        showtreeicon="true" textfield="SupName" idfield="Id" parentfield="pid" resultastree="false">
                    </ul>
                </div>
            </div>
            <div showcollapsebutton="true">
                <div id="datagrid1" class="mini-datagrid" url="/Archives/SearchGoodsArchiveList"
                    style="width: 100%; height: 100%;" idfield="id" allowresize="false" sizelist="[20,30,50,100]"
                    pagesize="20" multiselect="true">
                    <div property="columns">
                        <div type="indexcolumn" width="30">
                        </div>
                        <div type="checkcolumn" width="30">
                        </div>
                        <div name="SupName" field="SupName" headeralign="center" align="center" width="60">
                            供货商</div>
                        <div field="Id" headeralign="center" align="center" width="60">
                            店内码</div>
                        <div field="GoodsName" headeralign="center" align="center" width="60">
                            名称</div>
                        <div field="Specification" headeralign="center" align="center" width="40">
                            规格</div>
                        <div field="PyCode" headeralign="center" align="center" width="60">
                            拼音数字码</div>
                        <div field="GoodsBarCode" headeralign="center" align="center" width="60">
                            条形码</div>
                        <div field="PurchasePrice" headeralign="center" align="center" width="50" dataType="currency" currencyUnit="￥">
                            进价</div>
                        <div field="PriceHistory" headeralign="center" align="center" width="40"  renderer="onHistoryRenderer">
                            历史价格</div>
                        <div field="IfExamine" headeralign="center" align="center" width="30" renderer="onExamRender">审核</div>
                        <div name="action" width="60" headeralign="center" align="center" renderer="onActionRenderer"
                            cellstyle="padding:0;">
                            管理</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();


        var grid = mini.get("datagrid1");


        grid.load();
        //对"createtime"字段，进行降级排序
        grid.sortBy("Id", "desc");


        $("#key").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                search();
            }
        });



        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record.Id;
            var rowIndex = e.rowIndex;
            var s = "";
            if (record.IfExamine == "0") {
                s = ' <a class="Edit_Button" href="javascript:editRow(\'' + uid + '\')" >编辑</a>'
                + ' <a class="Delete_Button" href="javascript:if(confirm(\'确定要删除这条记录吗？\')){deleteItem(\'' + uid + '\')}">删除</a>';
            }
            else {
                s = ' <a class="Edit_Button" href="javascript:editRow(\'' + uid + '\')" >编辑</a>'
            }
            return s;
        }



        function remove() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                if (confirm("确定删除选中记录？")) {
                    var ids = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        ids.push(r.Id);
                    }
                    var id = ids.join(',');
                    grid.loading("操作中，请稍后......");
                    deleteItem(id);
                }
            } else {
                alert("请选中一条记录");
            }
        }
        function exame(obj, itemid, old) {
            $.ajax({
                url: "/Archives/GoodsExame/" + itemid,
                success: function (j) {
                    if (j == true) {
                        $(obj).css("color", "green").text("是");
                    }
                    else {
                        $(obj).css("color", "red").text("否");
                    }
                    $(obj).removeProp("onclick");
                    $(obj).unbind("click").click(function () {
                        exame(obj, itemid, !old)
                    })
                },
                error: function () {
                    alert("失败")
                }
            });
        }
    </script>
    <script type="text/javascript">
        mini.parse();
        var tree = mini.get("tree1");
        tree.on("nodeselect", function (e) {
            if (e.isLeaf) {
                grid.columns[2].visible = false;
                search();
            } else {
                grid.setData([]);
                grid.setTotalCount(0);
            }
        });
        function treesearch() {
            var value = mini.get("treekey").getValue();
            tree.load("/Archives/SearchAllSuppliers/" + value);
        }

        function showSearchWindow() {
            var win = mini.get("searchWindow");
            win.show();
        }
        function advSearch() {
            var frm = new mini.Form("frmAdv");
            grid.load(frm.getData(true));
            var win = mini.get("searchWindow");
            win.hide();
        }
        function search() {
            if (tree.getSelectedNode() != undefined) {
                grid.load({
                    "SupCode":tree.getSelectedNode().Id,
                    "key": mini.get("#Id").value,
                    "IfExamine": mini.get("#ifexame").value
                });
            }
            else {
                grid.load({
                    "key": mini.get("#Id").value,
                    "IfExamine": mini.get("#ifexame").value
                });
            }
        }
        function editRow(id) {
            var winTitle = "商品档案:";
            try {
                winTitle += grid.getSelected().SupName + " " + grid.getSelected().SupTel;
            }
            catch (e) { }
            var eUrl = "/Archives/GoodsEdit/" + id;
            if (tree.getSelectedNode() != undefined) {
                eUrl += "?SupCode=" + tree.getSelectedNode().Id;
            }
            mini.open({
                url: eUrl,
                title: winTitle,
                iconCls: "icon-user",
                allowResize: false,
                width: 700,
                height: 400,
                onload: function () {
                    //var iframe = this.getIFrameEl();
                    //var data = { action: "new" };
                    //iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
        function viewRow(id) {
            var winTitle = "商品档案:";
            try {
                winTitle += grid.getSelected().SupName + " " + grid.getSelected().SupTel;
            }
            catch (e) { }
            var eUrl = "/Query/ViewGoods/" + id;
            if (tree.getSelectedNode() != undefined) {
                eUrl += "?SupCode=" + tree.getSelectedNode().Id;
            }
            mini.open({
                url: eUrl,
                title: winTitle,
                iconCls: "icon-user",
                allowResize: false,
                width: 700,
                height: 370,
                onload: function () {
                    //var iframe = this.getIFrameEl();
                    //var data = { action: "new" };
                    //iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
        function deleteItem(id) {
            $.ajax({
                url: "/Archives/GoodsDelete",
                data: { ids: id },
                dataType: "json",
                success: function (j) {
                    if (j == false) {
                        if (confirm("将要删除的产品存在采购数据，删除后将影响整个系统运行，是否确认删除？") == true) {
                            $.getJSON("/Archives/GoodsDelete", { "ids": id, "confirm": "true" }, function (r) {
                                //alert(r);
                                grid.reload();
                            });
                        }
                    }
                    else {
                        grid.reload();
                    }

                },
                error: function () {
                }
            });
        }
        function onHistoryRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record.Id;
            var rowIndex = e.rowIndex;
            return "<a href='javascript:viewHistory(\"" + e.record.PriceHistory + "\")'>查看</a>"
        }
        function viewHistory(text) {
            var table = "<table class='mini-grid-table' border='1' cellpadding='0' cellspacing='0' style='border-color:gray;border:#d2d2d2 1px solid;border-collapse: collapse;'>";
            table += "<tr>";
            table += "<td>价格</td><td>时间</td>";
            table += "</tr>";
            var rows = text.split(",");
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].split("|")[0] == "undefined" || rows[i].split("|")[0] == "null") {
                    break;
                }
                table += "<tr>";
                table += "<td>" + rows[i].split("|")[0] + "</td><td>" + rows[i].split("|")[1] + "</td>";
                table += "</tr>";
            }

            table += "</table>";

            mini.showMessageBox({
                width: 250,
                title: "历史价格",
                buttons: ["ok"],
                //message: "自定义Html",
                html: table,
                showModal: false,
                callback: function (action) {
                    //alert(action);
                }
            });
        }
    </script>
</body>
</html>
